// miniprogram/pages/index/student/myself/myself.js
const db=wx.cloud.database()
Page({
  toChangePassword: function(){
    wx.navigateTo({
      url: 'change_password/change_password?_id='+this.data.student._id+'&ps='+this.data.student.student_obj.stu_password,
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    student: {},
    canEdit: true,
    btn: true
  },
  edit: function(){
    this.setData({canEdit: false})
  },
  cancel: function(){
    this.setData({canEdit: true,student: this.data.student})
  },
  save: function(event){
    const that=this;
    this.setData({btn:!this.data.btn})
    

    this.setData({canEdit: true})
    const value=event.detail.value;
    const stu_birth=value.stu_birth;
    const stu_location=value.stu_location;
    const stu_mail=value.stu_mail;
    const stu_phone=value.stu_phone;
    const stu_self=value.stu_self;
    const stu_hope_job=value.stu_hope_job;
    const stu_hope_location=value.stu_hope_location;
    const stu_hope_pay=value.stu_hope_pay;

    const student=this.data.student;
    student.student_obj.stu_birth=stu_birth
    student.student_obj.stu_location=stu_location
    student.student_obj.stu_mail=stu_mail
    student.student_obj.stu_phone=stu_phone
    student.student_obj.stu_self=stu_self
    student.student_obj.stu_hope_job=stu_hope_job
    student.student_obj.stu_hope_location=stu_hope_location
    student.student_obj.stu_hope_pay=stu_hope_pay
 
    db.collection('student').doc(that.data.student._id).update({
      data: {
        'student_obj.stu_birth': stu_birth,
        'student_obj.stu_location': stu_location,
        'student_obj.stu_mail': stu_mail,
        'student_obj.stu_phone': stu_phone,
        'student_obj.stu_self': stu_self,
        'student_obj.stu_hope_job': stu_hope_job,
        'student_obj.stu_hope_location': stu_hope_location,
        'student_obj.stu_hope_pay': stu_hope_pay
      }
    }).then(res=>{
       getApp().tos("保存成功")
       wx.navigateTo({
         url: '../student?obj='+encodeURIComponent(JSON.stringify(student))
       })
    })
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({student: JSON.parse(decodeURIComponent(options.student))})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({btn: false})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})